<template>
	<view class="chat-page-background">
		<view v-for="msg in msgList">
			<uni-dateformat :date="msg.createTime" format="yyyy-MM-dd hh:mm:ss" class="time-bar"></uni-dateformat>
			<view class="msg-bar">
				<image :src="msg.senderLogo ? msg.senderLogo : '../../static/logo.png'" class="msg-logo" style="width: 100rpx;"></image>
				<view class="send-msg-box">
					<view class="msg">{{msg.message}}</view>
				</view>
				<view class="msg-blank"></view>
			</view>
		</view>
	</view>
</template>

<script>
	import config from "@/config/app.js"
	export default {
		data() {
			return {
				id: "",
				message: "",
				receiverName: "",
				msgList: [],
				firstOpen: true
			};
		},
		methods: {
			getMsgList() {
				this.$request.request({
					url: "/systemMessage/getMessageList",
					method: "GET",
					data: {}
				}).then(res=>{
					if (res.code == 200) {
						for (let i=0; i<res.data.length; i++) {
							if (res.data[i].receiverLogo) {
								res.data[i].receiverLogo = config.IMG_URL + res.data[i].receiverLogo;
							} else {
								res.data[i].receiverLogo = '../../static/logo.png'
							}
							if (res.data[i].senderLogo) {
								res.data[i].senderLogo = config.IMG_URL + res.data[i].senderLogo;
							} else {
								res.data[i].senderLogo = '../../static/logo.png'
							}
						}
						this.msgList = res.data;
						this.$nextTick(function(){
							if (this.firstOpen) {
								uni.pageScrollTo({
										scrollTop: 99999999999
								})
								this.firstOpen = false
							}
						})
					}
				})
			}
		},
		mounted() {
		  this.timer = setInterval(this.getMsgList, 1000);
		},
		beforeDestroy() {
		  clearInterval(this.timer);
		},
		onLoad() {
		},
		onPullDownRefresh() {
			this.getMsgList();
			uni.stopPullDownRefresh();
		},
	}
</script>

<style lang="scss">

	.chat-page-background {
		background-color: #FFFFFF;
		padding-top: 40rpx;
		
		.time-bar {
			width: 100%;
			font-size: 14px;
			color: #999999;
			text-align: center;
			display: block;
		}
		
		.msg-bar {
			display: flex;
			padding: 20rpx;
			
			.msg-logo {
				width: 100prx;
				height: 100rpx;
				border-radius: 50rpx;
			}
			
			.send-msg-box {
				flex: 1;
				display: flex;
				align-items: center;
				justify-content: flex-start;
				
				.msg {
					margin-left: 20rpx;
					font-size: 30rpx;
					line-height: 44rpx;
					padding: 20rpx;
					background-color: #007AFF;
					color: #FFFFFF;
					border-radius: 20rpx;
					text-align: justify;
				}
			}
			
			.receive-msg-box {
				flex: 1;
				display: flex;
				align-items: center;
				justify-content: flex-end;
				
				.msg {
					margin-right: 20rpx;
					font-size: 30rpx;
					line-height: 44rpx;
					padding: 20rpx;
					background-color: #007AFF;
					color: #FFFFFF;
					border-radius: 20rpx;
					text-align: justify;
				}
			}
			
			
			.msg-blank {
				width: 100rpx;
			}
			
		}
		
		
		
	}
</style>
